home *** CD-ROM | disk | FTP | other *** search
- #include "stdafx.h"
-
- cWeapon *weapons = 0, *weapons_belowscreen = 0, *weapons_abovescreen = 0;
-
- cWeapon::cWeapon(int _x, int _y, cProperties *_orig, char *startseq)
- : cGameObject(_orig)
- {
- add((cList **)&weapons);
-
- // Set animation
-
- set_sequence(startseq, TRUE);
-
- // Set position
-
- set_position(_x, _y);
-
- // Set soundsequence
-
- set_soundsequence(startseq, TRUE);
-
- // Make sure object is drawn
-
- make_dirty();
-
- // Set other
-
- armor = orig->params->get_int("*ARMOR", 1);
- armor_power = orig->params->get_int("*ARMOR_POWER", 0);
- push_power = orig->params->get_int("*PUSH_POWER", 0);
- instant_push_speed = orig->params->get_fix("*INSTANT_PUSH_SPEED", 0);
- ignore_platforms = orig->params->get_fix("*IGNORE_PLATFORMS", 0) * sec;
- invulnerable = orig->params->get_bool("*INVULNERABLE", FALSE);
- parts_on_kill = orig->params->get_int("*PARTS_ON_KILL", 0);
- push_moving_direction = TRUE;
- move_object_after_hit = TRUE;
-
- owner = 0;
- }
-
- cWeapon::~cWeapon()
- {
- // Don't create effects when not on screen
-
- if (!y_on_screen())
- return;
-
- // Create effect
-
- cEffect *e = new cEffect (x, y, orig, "EXPLODE");
- e->set_rotation_angle(get_rotation_angle());
-
- // Make parts
-
- cParts::make(x, y, parts_on_kill);
- }
-
- int cWeapon::control()
- {
- cMovable::control();
-
- // Check if in inpenetrable wall and influenced by it
-
- if (influenced_by_inpenetrable && check_radial_boundaries(circle_bounds, structures, cStructure::check_inpenetrable) != 0)
- explode = TRUE;
-
- // Only derived classes should exist
-
- return FALSE;
- }
-
- void cWeapon::save()
- {
- cGameObject::save();
- }
-
- void cWeapon::hit(fix, cWeapon *w)
- {
- armor -= w->armor_power;
-
- if (armor <= 0)
- explode = TRUE;
- }
-
- static int hit_bubble(cMovable *_w, cDisplayable *_b, cCircle *, cCircle *)
- {
- cWeapon *w = (cWeapon *)_w;
- cBubble *b = (cBubble *)_b;
-
- // Hit
-
- b->hit(w);
-
- // Return
-
- return TRUE;
- }
-
- static int hit_player(cMovable *_w, cDisplayable *_c, cCircle *, cCircle *)
- {
- cWeapon *w = (cWeapon *)_w;
- cCharacter *c = (cCharacter *)_c;
-
- int was_active = c->is_active();
-
- // Hit
-
- c->hit(w->armor_power);
-
- // Push
-
- if (w->push_moving_direction)
- c->push(w->movement_direction(), w->push_power, w->instant_push_speed, w->ignore_platforms);
- else
- c->push(angle(c->x - w->x, c->y - w->y), w->push_power, w->instant_push_speed, w->ignore_platforms);
-
- // Score keeping
-
- if (was_active && w->owner != 0 && w->owner != c)
- w->owner->modify_score(w->score_value + (c->is_active()? 0 : 50), c);
-
- // Return
-
- return TRUE;
- }
-
- static int check_hit_weapon(cMovable *, cDisplayable *t, cCircle *, cCircle *)
- {
- return !((cWeapon *)t)->invulnerable;
- }
-
- static int hit_weapon(cMovable *_w, cDisplayable *_t, cCircle *, cCircle *)
- {
- cWeapon *w = (cWeapon *)_w;
- cWeapon *t = (cWeapon *)_t;
-
- if (!t->invulnerable)
- {
- if (w->push_moving_direction)
- t->hit(w->movement_direction(), w);
- else
- t->hit(angle(t->x - w->x, t->y - w->y), w);
-
- return TRUE;
- }
-
- return FALSE;
- }
-
- static int hit_bonus(cMovable *, cDisplayable *b, cCircle *, cCircle *)
- {
- ((cBonus *)b)->explode = TRUE;
-
- return TRUE;
- }
-
- int cWeapon::check_radial_hit_one(cCircle *c, int only_check)
- {
- cDisplayable *o = not_owner_timeout? owner : 0;
-
- return check_radial_boundaries(c, bubbles, only_check? 0 : hit_bubble, o, move_object_after_hit) != 0 ||
- check_radial_boundaries(c, players, only_check? 0 : hit_player, o, move_object_after_hit) != 0 ||
- check_radial_boundaries(c, weapons, only_check? check_hit_weapon : hit_weapon, o, move_object_after_hit) != 0 ||
- check_radial_boundaries(c, bonus, only_check? 0 : hit_bonus, o, move_object_after_hit) != 0;
- }
-
- int cWeapon::check_radial_hit_more(cCircle *c, int only_check)
- {
- cDisplayable *o = not_owner_timeout? owner : 0;
-
- int rv1 = check_radial_boundaries(c, bubbles, only_check? 0 : hit_bubble, o, move_object_after_hit) != 0,
- rv2 = check_radial_boundaries(c, players, only_check? 0 : hit_player, o, move_object_after_hit) != 0,
- rv3 = check_radial_boundaries(c, weapons, only_check? check_hit_weapon : hit_weapon, o, move_object_after_hit) != 0,
- rv4 = check_radial_boundaries(c, bonus, only_check? 0 : hit_bonus, o, move_object_after_hit) != 0;
-
- return rv1 || rv2 || rv3 || rv4;
- }
-